|
1
|
|
|
var LookupAPI = {}; |
|
2
|
|
|
|
|
3
|
|
|
LookupAPI.lookupMap = {}; |
|
4
|
|
|
|
|
5
|
|
|
LookupAPI.loadLookupData = function () { |
|
6
|
|
|
//DivisionAPI.getDivisions(locale); |
|
7
|
|
|
//BranchAPI.getBranches(locale); |
|
8
|
|
|
var locales = ["en_CA", "fr_CA"]; |
|
9
|
|
|
//var lookupTypes = ["department", "branch", "division", "province", "jobterm"]; |
|
10
|
|
|
var lookupTypes = ["department", "province", "jobterm", "skill_level", "experience_level", "clearance", "language"]; |
|
11
|
|
|
for (i in locales) { |
|
|
|
|
|
|
12
|
|
|
for (j in lookupTypes) { |
|
|
|
|
|
|
13
|
|
|
var locale = locales[i]; |
|
14
|
|
|
var lookupType = lookupTypes[j]; |
|
15
|
|
|
LookupAPI.getLookupData(lookupType, locale, null); |
|
16
|
|
|
} |
|
17
|
|
|
} |
|
18
|
|
|
}; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
LookupAPI.getLookupData = function (lookupType, locale, requestCallback) { |
|
22
|
|
|
var lookup_URL = DataAPI.baseURL + "/" + locale + "/Lookup/" + lookupType; |
|
|
|
|
|
|
23
|
|
|
DataAPI.sendRequest(lookup_URL, 'GET', {}, null, function(request){ |
|
24
|
|
|
LookupAPI.addToLookupMap(lookupType, locale, request.response); |
|
25
|
|
|
if (requestCallback) { |
|
26
|
|
|
requestCallback(request); |
|
27
|
|
|
} |
|
28
|
|
|
}); |
|
29
|
|
|
}; |
|
30
|
|
|
|
|
31
|
|
|
LookupAPI.addToLookupMap = function (lookupType, locale, response) { |
|
32
|
|
|
if (!LookupAPI.lookupMap[locale]) { |
|
33
|
|
|
LookupAPI.lookupMap[locale] = {}; |
|
34
|
|
|
} |
|
35
|
|
|
if (!LookupAPI.lookupMap[locale][lookupType]) { |
|
36
|
|
|
LookupAPI.lookupMap[locale][lookupType] = {}; |
|
37
|
|
|
} |
|
38
|
|
|
LookupAPI.lookupMap[locale][lookupType] = JSON.parse(response); |
|
39
|
|
|
}; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* If the requested lookupType is already in the lookupMap, send it to the lookupCallback |
|
43
|
|
|
* immediately. If not, request the lookup data, then call lookupCallback with |
|
44
|
|
|
* the response. |
|
45
|
|
|
* |
|
46
|
|
|
* @param {string} lookupType |
|
47
|
|
|
* @param {function} lookupCallback |
|
48
|
|
|
* @return {undefined} |
|
49
|
|
|
*/ |
|
50
|
|
|
LookupAPI.getLookupResponse = function (lookupType, lookupCallback) { |
|
51
|
|
|
var locale = TalentCloudAPI.getLanguageFromCookie(); |
|
|
|
|
|
|
52
|
|
|
if (!LookupAPI.lookupMap[locale]) { |
|
53
|
|
|
LookupAPI.lookupMap[locale] = {}; |
|
54
|
|
|
} |
|
55
|
|
|
if (LookupAPI.lookupMap[locale][lookupType]) { |
|
56
|
|
|
lookupCallback(LookupAPI.lookupMap[locale][lookupType]); |
|
57
|
|
|
} else { |
|
58
|
|
|
LookupAPI.getLookupData(lookupType, locale, function (request) { |
|
59
|
|
|
if (request.status === 200) { |
|
60
|
|
|
lookupCallback(LookupAPI.lookupMap[locale][lookupType]); |
|
61
|
|
|
} |
|
62
|
|
|
}); |
|
63
|
|
|
} |
|
64
|
|
|
}; |
|
65
|
|
|
|
|
66
|
|
|
LookupAPI.getLocalizedLookupValue = function (lookupType, valueId) { |
|
67
|
|
|
var locale = TalentCloudAPI.getLanguageFromCookie(); |
|
|
|
|
|
|
68
|
|
|
if (!LookupAPI.lookupMap[locale]) { |
|
69
|
|
|
LookupAPI.lookupMap[locale] = {}; |
|
70
|
|
|
} |
|
71
|
|
|
var elements = LookupAPI.lookupMap[locale][lookupType]; |
|
72
|
|
|
if (elements) { |
|
73
|
|
|
for (i in elements) { |
|
|
|
|
|
|
74
|
|
|
if (elements[i].id == valueId) { |
|
75
|
|
|
return elements[i].value; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} else { |
|
79
|
|
|
LookupAPI.getLookupData(lookupType, locale, function (request) { |
|
80
|
|
|
if (request.status === 200 && LookupAPI.lookupMap[locale][lookupType]) { |
|
|
|
|
|
|
81
|
|
|
elements = LookupAPI.lookupMap[locale][lookupType]; |
|
82
|
|
|
for (i in elements) { |
|
|
|
|
|
|
83
|
|
|
if (elements[i].id == valueId) { |
|
84
|
|
|
return elements[i].value; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
}); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return null; |
|
92
|
|
|
}; |
|
93
|
|
|
|
|
94
|
|
|
// populates elements passed by element id |
|
95
|
|
|
LookupAPI.populateDropdown = function (lookupType, elementId, useLookupValueAsOptionValue) { |
|
96
|
|
|
var selectElem = document.getElementById(elementId); |
|
97
|
|
|
if (selectElem) { |
|
98
|
|
|
var locale = TalentCloudAPI.getLanguageFromCookie(); |
|
|
|
|
|
|
99
|
|
|
if (!LookupAPI.lookupMap[locale]) { |
|
100
|
|
|
LookupAPI.lookupMap[locale] = {}; |
|
101
|
|
|
} |
|
102
|
|
|
var lookupList = LookupAPI.lookupMap[locale][lookupType]; |
|
103
|
|
|
if (lookupList) { |
|
104
|
|
|
Utilities.clearSelectOptions(selectElem); |
|
|
|
|
|
|
105
|
|
|
for (var item in lookupList) { |
|
|
|
|
|
|
106
|
|
|
var option = document.createElement("option"); |
|
107
|
|
|
if (useLookupValueAsOptionValue === true) { |
|
108
|
|
|
option.value = lookupList[item].value; |
|
109
|
|
|
} else { |
|
110
|
|
|
option.value = lookupList[item].id; |
|
111
|
|
|
} |
|
112
|
|
|
option.innerHTML = lookupList[item].value; |
|
113
|
|
|
selectElem.appendChild(option); |
|
114
|
|
|
} |
|
115
|
|
|
} else { |
|
116
|
|
|
LookupAPI.getLookupData(lookupType, locale, function (request) { |
|
|
|
|
|
|
117
|
|
|
if (LookupAPI.lookupMap[locale][lookupType]) { |
|
118
|
|
|
LookupAPI.populateDropdown(lookupType, elementId, useLookupValueAsOptionValue); |
|
119
|
|
|
} |
|
120
|
|
|
}); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
}; |
|
125
|
|
|
|
|
126
|
|
|
//Populates select elements passed directly |
|
127
|
|
|
LookupAPI.populateDropdownElement = function (lookupType, element, useLookupValueAsOptionValue) { |
|
128
|
|
|
if (element) { |
|
129
|
|
|
var locale = TalentCloudAPI.getLanguageFromCookie(); |
|
|
|
|
|
|
130
|
|
|
if (!LookupAPI.lookupMap[locale]) { |
|
131
|
|
|
LookupAPI.lookupMap[locale] = {}; |
|
132
|
|
|
} |
|
133
|
|
|
var lookupList = LookupAPI.lookupMap[locale][lookupType]; |
|
134
|
|
|
if (lookupList) { |
|
135
|
|
|
Utilities.clearSelectOptions(element); |
|
|
|
|
|
|
136
|
|
|
for (var item in lookupList) { |
|
|
|
|
|
|
137
|
|
|
var option = document.createElement("option"); |
|
138
|
|
|
if (useLookupValueAsOptionValue === true) { |
|
139
|
|
|
option.value = lookupList[item].value; |
|
140
|
|
|
} else { |
|
141
|
|
|
option.value = lookupList[item].id; |
|
142
|
|
|
} |
|
143
|
|
|
option.innerHTML = lookupList[item].value; |
|
144
|
|
|
element.appendChild(option); |
|
145
|
|
|
} |
|
146
|
|
|
} else { |
|
147
|
|
|
LookupAPI.getLookupData(lookupType, locale, function (request) { |
|
|
|
|
|
|
148
|
|
|
if (LookupAPI.lookupMap[locale][lookupType]) { |
|
149
|
|
|
LookupAPI.populateDropdownElement(lookupType, element, useLookupValueAsOptionValue); |
|
150
|
|
|
} |
|
151
|
|
|
}); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
}; |